package com.qn.meta.controlle;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import com.qn.common.base.BaseControlle;
import com.qn.common.base.model.ResponseMode;
import com.qn.core.resources.ResourcesSession;
import com.qn.meta.util.VisitorUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
@Tag(name = "测试API")
@SaCheckLogin
@RestController
@RequestMapping("test")
public class TestController extends BaseControlle {

    @Operation(summary = "登录测试")
    @SaIgnore
    @GetMapping("login")
    public ResponseMode login(HttpServletRequest request) {
        StpUtil.login(10001, new SaLoginModel()
                .setDevice(ResourcesSession.PC)
                .setIsLastingCookie(false));
        StpUtil.getSession().set(ResourcesSession.USER_AGENT, "张三");
        StpUtil.getSession().set(ResourcesSession.CLIENT_IP, VisitorUtil.getIp(request));
        StpUtil.getSession().set(ResourcesSession.CLIENT_LANGUAGE, VisitorUtil.getLanguage(request));
        StpUtil.getSession().set(ResourcesSession.USER_AGENT, VisitorUtil.getUserAgents(request));
        return success();
    }
    @Operation(summary = "退出登录")
    @SaIgnore
    @GetMapping("logout")
    public ResponseMode logout(HttpServletRequest request) {
        StpUtil.logout();
        return success();
    }
}
